﻿
namespace GLog
{
    public abstract class Log : ILog
    {
        private LogLevel _displayLevel;
        public ILog ChainedLog
        {
            get;
            set;
        }
        public Log(ILog postLog = null, LogLevel displayLevel = LogLevel.Message|LogLevel.Warning|LogLevel.Error)
        {
            ChainedLog = postLog;
            _displayLevel = displayLevel;
        }


        public abstract void Initial();

        public abstract void WriteLog();

        public void LogHeader(string message)
        {
            OutputHeader(message);
            if (ChainedLog != null)
            {
                ChainedLog.LogHeader(message);
            }
        }

        protected abstract void OutputHeader(string message);

        public virtual void LogMessage(string message)
        {
            if ((LogLevel.Message & _displayLevel) == LogLevel.Message)
            {
                LogMessage(message, LogLevel.Message);
                if (ChainedLog != null)
                {
                    ChainedLog.LogMessage(message);
                }
            }
        }

        public virtual void LogWarning(string warning)
        {
            if ((LogLevel.Warning & _displayLevel) == LogLevel.Warning)
            {
                LogMessage(warning, LogLevel.Warning);
                if (ChainedLog != null)
                {
                    ChainedLog.LogWarning(warning);
                }
            }
        }

        public virtual void LogError(string error)
        {
            if ((LogLevel.Error & _displayLevel) == LogLevel.Error)
            {
                LogMessage(error, LogLevel.Error);
                if (ChainedLog != null)
                {
                    ChainedLog.LogError(error);
                }
            }
        }

        internal abstract void LogMessage(string info, LogLevel level);
    }
}
